#include<bits/stdc++.h>
using namespace std;
const int N=(1<<20)+100;
using ll=long long;
using ul=unsigned long long;
using vt=vector<int>;
int T,n,m,a[N],b[N],ans;
int f[305][305][305],cntt;
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    freopen("build.in","r",stdin);
    freopen("build.out","w",stdout);
    int i,j,k,l,r,x,y,z,v;
    for(x=1,cin>>n;x<=n;++x)cin>>a[x];
    for(x=1;x<=n;++x)f[x][x][a[x]]=1;
    for(z=2;z<=n;++z)
        for(l=1,r=z;r<=n;++l,++r){
            for(k=z;k<=n;++k){
                f[l][r][k]=max({f[l+1][r][k]+(a[l]==k-z+1),
                               f[l][r-1][k]+(a[r]==k-z+1),
                               f[l+1][r][k-1]+(a[l]==k),
                               f[l][r-1][k-1]+(a[r]==k)});
            }
            for(k=z+1;k<=n;++k)if(f[l][r][k]!=f[l][r][k-1])++cntt;
        }
    printf("%d\n",n-f[1][n][n]);
    return 0;
}